package Person;
 
use DateTime;
use DateTime::Format::Natural;
use Moose;
use Moose::Util::TypeConstraints;
 
has name => (
    is       => 'rw',
    isa      => 'Str',
    required => 1,
);
 
# Moose doesn't know about non-Moose-based classes.
class_type 'DateTime';
 
my $en_parser = DateTime::Format::Natural->new(
    lang      => 'en',
    time_zone => 'UTC',
);
 
coerce 'DateTime'
    => from 'Str'
    => via { $en_parser->parse_datetime($_) };
 
has birth_date => (
    is      => 'rw',
    isa     => 'DateTime',
    coerce  => 1,
    handles => { birth_year => 'year' },
);
 
enum 'ShirtSize' => [qw( s m l xl xxl )];
 
has shirt_size => (
    is      => 'rw',
    isa     => 'ShirtSize',
    default => 'l',
);